local UI = {}

-- 判断是否某界面通用方法
local function isXXX(args)
  local x, y = LuaAuxLib.FindMultiColor(args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8])
  if x > 0 and y > 0 then
    return true, -1, -1
  end
  return false, x, y
end

-- 判断是否在府宅界面
UI.isFuzhai = function()
  local args = {589, 0, 733, 75, "42C9EF", "4|-39|0F1FA4,-39|25|122AC1,30|26|0E1FB0,77|-33|2682E5,77|-9|60E4F8", 0, 0.9}
  return isXXX(args)
end

-- 判断是否是经营界面
UI.isJingying = function()
  local args = {45, 53, 552, 195, "9FE9FE", "23|-5|BCF4FE,39|2|00082B,61|-5|BAF1FB,89|0|00082C,115|-3|B0EFFE,-226|83|86D8F7,3|76|2DB8EA,212|87|6B7D87", 0, 0.9}
  return isXXX(args)
end

-- 判断是否在大地图
UI.isDaditu = function()
  local args = {0, 0, 0, 0, "01D0EF", "-2|7|064A94,-5|27|003258,-16|13|13126F,-58|21|1B1AA5,-83|1|0C11C6", 0, 0.9}
  return isXXX(args)
end

-- 判断是否在关卡界面
UI.isGuanka = function()
  return LuaAuxLib.CmpColorEx("680|92|38D7FE,659|91|0C159C,492|92|1F246B,262|90|000935,181|90|1F246B,164|89|2589D0,60|86|BBF3FE", 0.9) == 1
end

-- 判断是否在关卡（战斗中）界面
UI.isGuanka_zhangdouzhong = function()
  return LuaAuxLib.CmpColorEx("661|153|4BE3FE,681|92|1C6D80,614|87|101135,458|90|00051C,164|90|134569,60|87|5C7B80", 0.9) == 1
end

-- 判断是否在关卡（战斗结束）界面
UI.isGuanka_zhangdoujiesu = function()
  return LuaAuxLib.CmpColorEx("669|166|267380,680|89|113941,656|92|030426,481|94|080A1D,264|92|00030E,165|90|0A2335,60|87|2F3E41", 0.9) == 1
end

-- 判断是否在关卡（对话）界面
UI.isGuanka_duihua = function()
  return LuaAuxLib.CmpColorEx("682|92|228299,528|91|121844,263|92|000621,167|88|16537E,58|88|6A9299,12|1037|050504,473|1027|76CEEF,172|1246|76CEEF", 0.9) == 1
end

-- 判断是否在关卡（BOSS）界面
UI.isGuanka_boss = function()
  return LuaAuxLib.CmpColorEx("337|597|1CDFFB,354|591|00009B,400|579|FCFCFC,400|601|C2C2C2,423|593|00007E,282|601|12D0FA,257|604|0A147C", 0.9) == 1
end

-- 判断是否在关卡（BOSS战结束）界面
UI.isGuanka_bossJiesu = function()
  return LuaAuxLib.CmpColorEx("685|65|0D2D7A,705|52|055A7E,645|57|5E7980,607|54|01071C,624|74|396573,407|764|6DAABD", 0.9) == 1
end

-- 判断是否在关卡（BOSS中场）界面
UI.isGuanka_bossZhongchang = function()
  return LuaAuxLib.CmpColorEx("705|50|04647F,686|67|0E2679,644|57|5E7980,608|54|000519,428|402|04CAF8,426|518|56F8FA,369|481|68A4B6,319|447|09FEFE,335|407|0059DA", 0.9) == 1
end

-- 判断是否在关卡（BOSS失败）界面
UI.isGuanka_bossShibai = function()
  return LuaAuxLib.CmpColorEx("704|51|32C6FA,685|66|1A51F1,607|54|020E38,645|58|BAEFFE,300|842|A9EFF2,351|840|AAF0F3,383|846|A8EEF1,417|851|A7ECEF,340|985|373B7B,586|1170|908A8B", 0.9) == 1
end

-- 判断是否在关卡(下一关)界面
UI.isGuanka_next = function()
  return LuaAuxLib.CmpColorEx("199|239|4F3116,546|249|A25B51,697|466|8B5447,538|808|8A5446,25|467|8B5447,186|874|000000,398|955|DFF1FF", 0.9) == 1
end

-- 获取当前所在界面
UI.getCurrentUI = function()
  if UI.isFuzhai() then
    return "府宅"
  elseif UI.isJingying() then
    return "经营"
  elseif UI.isDaditu() then
    return "大地图"
  elseif UI.isGuanka() then
    return "关卡"
  elseif UI.isGuanka_zhangdouzhong() then
    return "关卡_战斗中"
  elseif UI.isGuanka_zhangdoujiesu() then
    return "关卡_战斗结束"
  elseif UI.isGuanka_duihua() then
    return "关卡_对话"
  elseif UI.isGuanka_boss() then
    return "关卡_BOSS"
  elseif UI.isGuanka_bossZhongchang() then
    return "关卡_BOSS战结束"
  elseif UI.isGuanka_bossJiesu() then
    return "关卡_BOSS中场"
  elseif UI.isGuanka_bossShibai() then
    return "关卡_BOSS失败"
  elseif UI.isGuanka_next() then
    return "关卡_下一关"
  end
  return "未知"
end

function QMPlugin.RegisterModule()
  LuaAuxLib.Modules = LuaAuxLib.Modules or {}
  LuaAuxLib.Modules.Jp_UI = UI
end
